<script type="text/javascript" language="javascript">
function show()
{
	document.nnf.action="index.php?tc=news_add";
	document.nnf.submit();
}
</script>
<form name="nnf" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td width="46%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">News</span>&nbsp; 
	
	</td>
	<td width="40%" align="right" class="font12">
   <a href="index.php?tc=news_add" class="font12">Add News</a>  
    <!-- <a href="index.php?tc=addnewscatg" class="font12">Add Category</a>--></td>
	<td width="14%" align="right"><select name="_st" onchange="window.location='index.php?tc=news&page=<?php echo $_REQUEST['page'];?>&_st='+this.value">
	  <option value="" <?php if($_REQUEST['_st']=="") echo "selected";?>><--Sort--></option>
	  <option value="2" <?php if($_REQUEST['_st']==2) echo "selected";?>>All</option>
	  <option value="1" <?php if($_REQUEST['_st']==1) echo "selected";?>>Approved Ads</option>
	  <option value="3" <?php if($_REQUEST['_st']==3) echo "selected";?>>Pending Ads</option>
	  </select></td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
</form>
	<?php
if($_REQUEST['_s'] == 2)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Deleted Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<table width="100%" align="center" border="0" class="list">
<thead>
<tr>
	<td align="center" width="30">#</td>
	<td align="center" width="250">Title</td>
    <td align="center" width="200">Organisation Name</td>
    <td align="center" width="120">Category</td>
    <td align="center" width="150">Submitted Date</td>
    <td align="center" width="50">Status</td>
    <td align="center">Action</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=news&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];

if($st == "" || $st == 2)
{
	$res = mysql_query("select Id from news");
	
	$query = mysql_query("select Id,Organisation, Title, Category, DATE_FORMAT(CreatedDate,'%d-%m-%Y') as insdate, Status from news order by Id desc limit $offset , $rowsPerPage") or die(mysql_error());
}
else
{
	if($st == 3) $st=0;
	$res = mysql_query("select Id from ads where Status='$st'");
	
	$query = mysql_query("select Id,Organisation, Title, Category, DATE_FORMAT(CreatedDate,'%d-%m-%Y') as insdate, Status from news where Status='$st' order by Id desc limit $offset , $rowsPerPage");
}
$i = 1;
while($q = mysql_fetch_array($query))
{ 

	
	if($q["Status"] == 1) $status = "<img src='../images/unlock.gif'>";
	else $status ="<img src='../images/lock.gif'>";
	?>
    <tr class="font12">
        <td align="center"><?php echo $i+$offset;?></td>
        <td align="left"><?php echo $q["Title"];?></td>
        <td align="left"><?php echo $q["Organisation"];?></td>
        <td align="left"><?php echo $q["Category"];?></td>
        <td align="center"><?php echo $q["insdate"];?></td>
        <td align="center"><?php echo $status;?></td>
        <td align="center"><a href="index.php?tc=news_view&_d=<?php echo $q['Id'];?>&page=<?php echo $pageNum;?>" class="font12"> <img src="../images/pencil.png" border="0" /></a> &nbsp;	&nbsp;	&nbsp;	<a href="index.php?tc=news_view&_d=<?php echo $q['Id'];?>&_a=d&page=<?php echo $pageNum;?>" onclick="return confirm('Are you sure want to delete?')" class="font12"><img src="../images/cross.png" border="0" /></a>
        </td>
   	</tr>     
<?php 
	$i++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="7" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>    